package com.bootdo.blog.dao;

import com.bootdo.blog.domain.IrrigationDO;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
/**
 * 
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2021-03-07 10:38:32
 */
@Mapper
public interface IrrigationMapper {

	@Select("select `irri_id`, `batch`, `irrigation_time`, `long_time`, `irrigation_volume`, `content`, `water_origin`, `principal`, `telephone` from tb_irrigation where irri_id = #{id}")
	IrrigationDO get(Integer irriId);
	
	@Select("<script>" +
	"select * from tb_irrigation " + 
			"<where>" + 
		  		  "<if test=\"irriId != null and irriId != ''\">"+ "and irri_id = #{irriId} " + "</if>" + 
		  		  "<if test=\"batch != null and batch != ''\">"+ "and batch = #{batch} " + "</if>" + 
		  		  "<if test=\"irrigationTime != null and irrigationTime != ''\">"+ "and irrigation_time = #{irrigationTime} " + "</if>" + 
		  		  "<if test=\"longTime != null and longTime != ''\">"+ "and long_time = #{longTime} " + "</if>" + 
		  		  "<if test=\"irrigationVolume != null and irrigationVolume != ''\">"+ "and irrigation_volume = #{irrigationVolume} " + "</if>" + 
		  		  "<if test=\"content != null and content != ''\">"+ "and content = #{content} " + "</if>" + 
		  		  "<if test=\"waterOrigin != null and waterOrigin != ''\">"+ "and water_origin = #{waterOrigin} " + "</if>" + 
		  		  "<if test=\"principal != null and principal != ''\">"+ "and principal = #{principal} " + "</if>" + 
		  		  "<if test=\"telephone != null and telephone != ''\">"+ "and telephone = #{telephone} " + "</if>" + 
		  			"</where>"+ 
			" <choose>" + 
	            "<when test=\"sort != null and sort.trim() != ''\">" + 
	                "order by ${sort} ${order}" + 
	            "</when>" + 
				"<otherwise>" + 
	                "order by irri_id desc" + 
				"</otherwise>" + 
	        "</choose>"+
			"<if test=\"offset != null and limit != null\">"+
			"limit #{offset}, #{limit}" + 
			"</if>"+
			"</script>")
	List<IrrigationDO> list(Map<String, Object> map);
	
	@Select("<script>" +
	"select count(*) from tb_irrigation " + 
			"<where>" + 
		  		  "<if test=\"irriId != null and irriId != ''\">"+ "and irri_id = #{irriId} " + "</if>" + 
		  		  "<if test=\"batch != null and batch != ''\">"+ "and batch = #{batch} " + "</if>" + 
		  		  "<if test=\"irrigationTime != null and irrigationTime != ''\">"+ "and irrigation_time = #{irrigationTime} " + "</if>" + 
		  		  "<if test=\"longTime != null and longTime != ''\">"+ "and long_time = #{longTime} " + "</if>" + 
		  		  "<if test=\"irrigationVolume != null and irrigationVolume != ''\">"+ "and irrigation_volume = #{irrigationVolume} " + "</if>" + 
		  		  "<if test=\"content != null and content != ''\">"+ "and content = #{content} " + "</if>" + 
		  		  "<if test=\"waterOrigin != null and waterOrigin != ''\">"+ "and water_origin = #{waterOrigin} " + "</if>" + 
		  		  "<if test=\"principal != null and principal != ''\">"+ "and principal = #{principal} " + "</if>" + 
		  		  "<if test=\"telephone != null and telephone != ''\">"+ "and telephone = #{telephone} " + "</if>" + 
		  			"</where>"+ 
			"</script>")
	int count(Map<String, Object> map);
	
	@Insert("insert into tb_irrigation (`batch`, `irrigation_time`, `long_time`, `irrigation_volume`, `content`, `water_origin`, `principal`, `telephone`)"
	+ "values (#{batch}, #{irrigationTime}, #{longTime}, #{irrigationVolume}, #{content}, #{waterOrigin}, #{principal}, #{telephone})")
	int save(IrrigationDO irrigation);
	
	@Update("<script>"+ 
			"update tb_irrigation " + 
					"<set>" + 
		            "<if test=\"irriId != null\">`irri_id` = #{irriId}, </if>" + 
                    "<if test=\"batch != null\">`batch` = #{batch}, </if>" + 
                    "<if test=\"irrigationTime != null\">`irrigation_time` = #{irrigationTime}, </if>" + 
                    "<if test=\"longTime != null\">`long_time` = #{longTime}, </if>" + 
                    "<if test=\"irrigationVolume != null\">`irrigation_volume` = #{irrigationVolume}, </if>" + 
                    "<if test=\"content != null\">`content` = #{content}, </if>" + 
                    "<if test=\"waterOrigin != null\">`water_origin` = #{waterOrigin}, </if>" + 
                    "<if test=\"principal != null\">`principal` = #{principal}, </if>" + 
                    "<if test=\"telephone != null\">`telephone` = #{telephone}, </if>" + 
          					"</set>" + 
					"where irri_id = #{irriId}"+
			"</script>")
	int update(IrrigationDO irrigation);
	
	@Delete("delete from tb_irrigation where irri_id =#{irriId}")
	int remove(Integer irri_id);
	
	@Delete("<script>"+ 
			"delete from tb_irrigation where irri_id in " + 
					"<foreach item=\"irriId\" collection=\"array\" open=\"(\" separator=\",\" close=\")\">" + 
						"#{irriId}" + 
					"</foreach>"+
			"</script>")
	int batchRemove(Integer[] irriIds);
}
